<?php
require_once('libraries/pagination.php');

//phân trang
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$page = ($page>0) ? $page : 1;
$limit = 10;
$offset = ($page-1) * $limit;

$url = 'index.php?r=articles/index';

$options = array(
    'limit' => $limit,
    'offset' => $offset,
    'order_by' => 'id DESC'
);

$total_rows = get_total('articles', $options);
$total = ceil($total_rows / $limit);

//dữ liệu
$title = 'Tin tức';
$articles = get_all('articles', $options);
$pagination = pagination($url, $page, $total);
$categories = get_all('categories', array(
    'order_by' => 'position ASC'
));

//load view
$_content = 'frontend/views/articles/index.phtml';
require('frontend/views/common/layout.phtml');